package jdklearn.nio.读文件;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;

/**
 * create at 2018/10/23
 * author: suveng
 * email: suveng@163.com
 **/
public class Main {
    public static void main(String[] args) throws IOException {
//    获取通道
        FileInputStream fileInputStream = new FileInputStream("README.md");
        FileChannel channel = fileInputStream.getChannel();
//    创建缓冲区
        ByteBuffer byteBuffer=ByteBuffer.allocate(1024);
//    将数据读取到缓冲区
        channel.read(byteBuffer);

        System.out.println(new String(byteBuffer.array(), Charset.forName("utf-8")));
    }

}
